
// export function delay() {
//   let timer = 0
//   return function(callback, ms) {
//     clearTimeout(timer)
//     timer = setTimeout(callback, ms)
//   }
// }

export function formatMMSS(value) {
  let seconds = value % 60;
  let mins = ((value - seconds)) / 60;
  if (seconds < 10) {
    seconds = "0" + seconds;
  }
  if (mins === 0) {
    return "00:" + seconds;
  } else {
    if (mins < 10) {
      mins = "0" + mins;
    }
    return mins + ":" + seconds;
  }
}

export function formatMMSSss(value) {
  let ss = value % 1000;
  value = value / 1000;
  let seconds = value % 60;
  let mins = ((value - seconds)) / 60;
  if (seconds < 10) {
    seconds = "0" + seconds;
  }
  if (mins === 0) {
    return "00:" + seconds;
  } else {
    if (mins < 10) {
      mins = "0" + mins;
    }
    return mins + ":" + seconds + ":" + ss;
  }
}


export function isEmptyObject(value) {
  return value === null || value === undefined;
}

export function isEmptyArray(value) {
  return value === null || value === undefined || value.length === 0;
}

export function isEmptyStr(value) {
  return value === null || value === undefined || value === "";
}

export function arrayContains(array, value) {
  if (isEmptyObject(array)) {
    return false;
  }
  for (const arrayElement of array) {
    if (arrayElement.toUpperCase() === value.toUpperCase()) {
      return true;
    }
  }
  return false;
}


export function delay(delayTime) {
  let currentTime = new Date().getTime();
  let flag = true;
  while (flag) {
    if(new Date().getTime() - currentTime > delayTime) {
      flag = false;
    }
  }
}

export function arrayAndAndTruncateLastN(arr, data, n) {
  arr.push(data);
  if (arr.length <= n) {
    return arr;
  }
  return arr.splice(1)
}

export const receiveJson = {
  "5100": 4,  // 拉力
  "5101": 4,   // 位移
  "5102": 4,
  "5103": 4,
  "5104": 4,

};

export const nameRegisterJSON = {
  "lali" : "5100",
  "first": "5101",
  "second": "5102",
  "third": "5103",
  "step": "5104",
  "distance": "5105",

}

export const stepValueJson = {
  "init" : 0,
  "down": 1,
  "timeDown": 2,
  "up": 3,
  "finish": 4
}

export const stepValueStepIndexJson = {
  "0" : -1,
  "1": 0,
  "2": 1,
  "3": 2,
  "4": 3
}

export const settingRegisterSizeJSON = {
  "5100": 4,  // 电流设定
  "5201": 4,  // 未知数字1
};


export const settingArray = ["5100", "5101"];

